//package com.example.saas.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
//import com.example.saas.config.properties.DruidProperties;
//import com.example.saas.config.properties.MasterDataSourceProperties;
//import com.example.saas.datasource.DynamicDataSource;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//
//import javax.annotation.Resource;
//import javax.sql.DataSource;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 写法二：Druid配置
// */
//@Configuration
//public class DruidConfig {
//
//
//    @Resource
//    private DruidProperties druidProperties;
//    @Resource
//    private MasterDataSourceProperties masterDataSourceProperties;
//
//
//    /**
//     * 主数据源
//     */
//    @Bean
//    public DataSource masterDataSource() {
//        DruidDataSource druidDataSource = DruidDataSourceBuilder.create().build();
//        druidDataSource.setDriverClassName(masterDataSourceProperties.getDriverClassName());
//        druidDataSource.setUrl(masterDataSourceProperties.getUrl());
//        druidDataSource.setUsername(masterDataSourceProperties.getUsername());
//        druidDataSource.setPassword(masterDataSourceProperties.getPassword());
//        druidDataSource.setInitialSize(druidProperties.getInitialSize());
//        druidDataSource.setMinIdle(druidProperties.getMinIdle());
//        druidDataSource.setMaxActive(druidProperties.getMaxActive());
//        druidDataSource.setMaxWait(druidProperties.getMaxWait());
//        druidDataSource.setConnectTimeout(druidProperties.getConnectTimeout());
//        druidDataSource.setSocketTimeout(druidProperties.getSocketTimeout());
//        druidDataSource.setTimeBetweenEvictionRunsMillis(druidProperties.getTimeBetweenEvictionRunsMillis());
//        druidDataSource.setMinEvictableIdleTimeMillis(druidProperties.getMinEvictableIdleTimeMillis());
//        druidDataSource.setMaxEvictableIdleTimeMillis(druidProperties.getMaxEvictableIdleTimeMillis());
//        druidDataSource.setValidationQuery(druidProperties.getValidationQuery());
//        return druidDataSource;
//    }
//
//
//    @Primary
//    @Bean(name = "dynamicDataSource")
//    public DynamicDataSource dataSource(DataSource masterDataSource){
//        Map<Object, Object> targetDataSources = new HashMap<>();
//        targetDataSources.put("master", masterDataSource);
//        // TODO 可初始化预热数据源
//        return new DynamicDataSource(masterDataSource, targetDataSources);
//    }
//}
